package com.ustb.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ustb.springboot.common.utils.R;
import com.ustb.springboot.common.utils.TokenUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.ustb.springboot.dao.QuestionCheckboxDao;
import com.ustb.springboot.entity.QuestionCheckboxEntity;
import com.ustb.springboot.service.QuestionCheckboxService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


@Service("questionCheckboxService")
public class QuestionCheckboxServiceImpl extends ServiceImpl<QuestionCheckboxDao, QuestionCheckboxEntity> implements QuestionCheckboxService {


    @Resource
    private QuestionCheckboxDao questionCheckboxDao;

    @Override
    public R save(HttpServletRequest request, QuestionCheckboxEntity questionCheckbox) {
        questionCheckbox.setUserId(TokenUtil.getId(request));
        return this.save(questionCheckbox) ? R.ok(20000, "保存成功") : R.error(2000, "保存失败");
    }

    public R delete(Map<String, Object> body) {
        QueryWrapper<QuestionCheckboxEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", body.get("id"));
        return questionCheckboxDao.delete(queryWrapper) == 1 ? R.ok(20000, "删除成功！") : R.error(2000, "删除失败！");
    }

    @Override
    public List<QuestionCheckboxEntity> queryWithId(Map<String, Object> body) {
        QueryWrapper<QuestionCheckboxEntity>queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("id",body.get(body.get("id")));
        List<QuestionCheckboxEntity> questionCheckboxEntityList = questionCheckboxDao.selectList(queryWrapper);
        return questionCheckboxEntityList;
    }

}